package com.css.apps.base.user.action.relate;

import java.util.ArrayList;
import java.util.List;

import com.css.apps.base.user.action.UserAction;
import com.css.db.query.QueryCache;
import com.opensymphony.xwork.Action;

import net.sf.json.JSONObject;

@SuppressWarnings("serial")
public class GetUserRelateGroupTree extends UserAction {
	
	private String group_nodes;

	@SuppressWarnings("unchecked")
	@Override
	protected String userGo() {
		List<Object[]> aList = new QueryCache("select uuid, name from UserRelateGroup where userId=:userId")
			.setParameter("userId", sUser.getUserId()).list();
		List<JSONObject> ja = new ArrayList<>();
		JSONObject one = new JSONObject();
		one.put("id", "0");
		one.put("name", "默认分组");
		one.put("isParent", true);
		ja.add(one);
		for(Object[] arr : aList) {
			one = new JSONObject();
			one.put("id", arr[0]);
			one.put("name", arr[1]);
			one.put("isParent", true);
			ja.add(one);
		}
		group_nodes = ja.toString();
		return Action.SUCCESS;
	}
	public String getGroup_nodes() {
		return group_nodes;
	}
	public void setGroup_nodes(String groupNodes) {
		group_nodes = groupNodes;
	}
	
}
